<?php 
class calendrier_raid{

	var $id;
	var $idLieu;
	var $ts;
	var $description;
	var $valide;
	var $lieu;

	function calendrier_raid($var){
		global $sql;
		
		if(is_numeric($var)){
			$var=$sql->request_single("select * from ".CFG_MYSQL_PREFIX."calendrier_raid where id=".$var);
		}
		
		if(is_object($var)){
			$this->id=$var->id;
			$this->idLieu=$var->idLieu;
			$this->ts=$var->ts;
			$this->description=$var->description;
			$this->valide=$var->valide;
		}
		if(is_array($var)){
			$this->id=$var["id"];
			$this->idLieu=$var["idLieu"];
			$this->ts=$var["ts"];
			$this->description=$var["description"];
			$this->valide=$var["valide"];
		}
		
		$this->lieu=$sql->request_single("select * from ".CFG_MYSQL_PREFIX."lieu where id=".$this->idLieu);
	}

	function get_id(){ return stripslashes($this->id); }
	function set_id($value){ $this->id=$value; }
	function get_idLieu(){ return stripslashes($this->idLieu); }
	function set_idLieu($value){ $this->idLieu=$value; }
	function get_ts(){ return stripslashes($this->ts); }
	function set_ts($value){ $this->ts=$value; }
	function get_description(){ return stripslashes($this->description); }
	function set_description($value){ $this->description=$value; }
	function get_valide(){ return stripslashes($this->valide); }
	function set_valide($value){ $this->valide=$value; }


	function ajouter(){
		global $sql;
		$sqlr="insert into ".CFG_MYSQL_PREFIX."calendrier_raid(idLieu,ts,description,valide) values('".addslashes($this->idLieu)."','".addslashes($this->ts)."','".addslashes($this->description)."','".addslashes($this->valide)."')";
		$sql->query($sqlr,0);
	}

	function maj(){
		global $sql;
		$sql->query("update ".CFG_MYSQL_PREFIX."calendrier_raid set idLieu='".addslashes($this->idLieu)."',ts='".addslashes($this->ts)."',description='".addslashes($this->description)."',valide='".addslashes($this->valide)."' where id=".$this->id,0);
	}

	function supprimer(){
		global $sql;
		$sql->query("delete from ".CFG_MYSQL_PREFIX."calendrier_raid_compo where idRaid=".$this->id);
		$sql->query("delete from ".CFG_MYSQL_PREFIX."calendrier_raid where id=".$this->id);
	}
	
	function getCompo(){
		global $sql;
		
		$tmp=array(1=>array(),2=>array(),3=>array(),4=>array(),5=>array());
		$res=$sql->request("select * from ".CFG_MYSQL_PREFIX."calendrier_raid_compo where idRaid=".$this->id);
		foreach($res as $var){
			$dispo=$sql->request_single("select * from ".CFG_MYSQL_PREFIX."dispo where idPlayer=".$var->idPlayer." and ts=".$this->ts);
			
			if(!isset($tmp[$var->type][$var->place])) $tmp[$var->type][$var->place]=array();
			$tmp[$var->type][$var->place][]=array("dispo"=>$dispo, "player"=>new player($var->idPlayer));
		}
		
		return $tmp;
	}
	
	function getMaxPlace(){
		global $sql;
		
		$var=$sql->request_single("select max(place) as m from ".CFG_MYSQL_PREFIX."calendrier_raid_compo where idRaid=".$this->id);
		if($var->m!=null) return $var->m;
		else return 0;
	}
	
}